#ifndef COMMON_H
#define COMMON_H

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#ifdef WIN32
#include <windows.h>
#endif

#include <SDL.h>
#include <SDL_ttf.h>
#include <SDL_draw.h>
#include <string>
#include <vector>
#include <iostream>
#include <sstream>
#include <fstream>
using namespace std;

#define WQX_ORG_WIDTH		160
#define WQX_ORG_HEIGHT		80
#define WINDOW_WIDTH		480
#define WINDOW_HEIGHT		240
#define SAVE_FILE			L"GMUDSAVEFILE"
#define SAVE_SIZE			0x153
#define CONF_FILE			L"Key.conf"
#define SAVE_PREFIX			L"./"
#define GMUD_PREFIX			"./res/"
#define SINGLEFILE 0
#define Classic 0
#ifdef _DEBUG
#define WINDOW_TITLE		"SDLGmud(DEBUG)"
#else
#define WINDOW_TITLE		"SDLGmud(GoldGmud)"
#endif

#ifdef _DEBUG

typedef char GCHAR;
typedef unsigned char GUCHAR;
typedef short GSHORT;
typedef unsigned short GUSHORT;
typedef int GINT;
typedef unsigned int GUINT;

#else
#define DEBUG_CLIENTBLOCK
static unsigned int KEY_SEED = 7;
template <typename T>
class MyType
{
public:
	MyType()
	{
		KEY = ++KEY_SEED;
		data = 0 ^ KEY;
	};

	MyType(T i)
	{
		KEY = ++KEY_SEED;
		data = i ^ KEY;
	};

	T operator = (T i)
	{
		KEY = ++KEY_SEED;
		data = i ^ KEY;
		return i;
	};

	void operator += (T i)
	{
		data = (data ^ KEY) + i;
		KEY = ++KEY_SEED;
		data ^= KEY;
	};
	void operator -= (T i)
	{
		data = (data^KEY) - i;
		KEY = ++KEY_SEED;
		data ^= KEY;
	};
	void operator *= (T i)
	{
		data ^= KEY;
		data *= i;
		KEY = ++KEY_SEED;
		data ^= KEY;
	};
	void operator /= (T i)
	{
		data ^= KEY;
		data /= i;
		KEY = ++KEY_SEED;
		data ^= KEY;
	};
	void operator %= (T i)
	{
		data ^= KEY;
		data %= i;
		KEY = ++KEY_SEED;
		data ^= KEY;
	};
	void operator &= (T i)
	{
		data ^= KEY;
		data &= i;
		KEY = ++KEY_SEED;
		data ^= KEY;
	};
	
	T operator + (T i)
	{
		return i + (data ^ KEY);
	};

	T operator - (T i)
	{
		return (data ^ KEY) - i;
	};

	T operator * (T i)
	{
		return i * (data ^ KEY);
	};

	T operator / (T i)
	{
		return (data ^ KEY) / i;
	};
	
	void MyType::operator ++()
	{
		data = (data^KEY) + 1;
		KEY = ++KEY_SEED;
		data ^= KEY;
	};
	void MyType::operator --()
	{
		data = (data^KEY) - 1;
		KEY = ++KEY_SEED;
		data ^= KEY;
	};

	bool MyType::operator >(T i)
	{
		return (data ^ KEY) > i;
	};

	bool MyType::operator >=(T i)
	{
		return (data ^ KEY) >= i;
	};

	bool MyType::operator ==(T i)
	{
		return (data ^ KEY) == i;
	};
	bool MyType::operator !=(T i)
	{
		return (data ^ KEY) != i;
	};
	bool MyType::operator <(T i)
	{
		return (data ^ KEY) < i;
	};
	bool MyType::operator <=(T i)
	{
		return (data ^ KEY) <= i;
	};
	operator T()
	{
		return (this->data^KEY);
	};
private:
	T data;
	unsigned int KEY;
};

typedef MyType<char> GCHAR;
typedef MyType<unsigned char> GUCHAR;
typedef MyType<short> GSHORT;
typedef MyType<unsigned short> GUSHORT;
typedef MyType<int> GINT;
typedef MyType<unsigned int> GUINT;
#endif

#endif